// pages/setting/setting.js
const utils = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array: [
      {id: 4, index: 0, course_num: 226, class_id: 45090,  name: '四级必备'},
      {id: 4, index: 1, course_num: 35, class_id: 83369,  name: '四级救命'},
      {id: 6, index: 2, course_num: 105, class_id: 22957, name: '六级必备'},
      {id: 6, index: 3, course_num: 25, class_id: 60268, name: '六级救命'}],
    index: 0,
    planDays: 0,
    planWords: 0,
    reviewWords: 0
  },

  logoutBtn: function() {
    wx.showModal({
        title: '提示',
        content: '确认退出登录',
        success: function(res) {
            if(res.confirm === true) {
                console.log('退出登录', res);
            } else {
                console.log('取消退出', res);
            }
        }
    });
  },
  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    });
    wx.setStorageSync(utils.wordType, this.data.array[e.detail.value]);
  },

  planDaysInput: function(e) {
    console.log('设置计划学习天数',e.detail.value);
    this.setData({planWords: e.detail.value});
    wx.setStorageSync(utils.planStudyDays, e.detail.value);
  },

  planWordsInput: function(e) {
    console.log('设置每天学习单词个数', e.detail.value);
    this.setData({planStudyWordsOfDay: e.detail.value});
    wx.setStorageSync(utils.planStudyWordsOfDay, e.detail.value);
  },

  reviewWordsInput: function(e) {
    console.log('设置每天复习单词个数', e.detail.value);
    this.setData({reviewWords: e.detail.value});
    wx.setStorageSync(utils.planReviewWordsOfDay, e.detail.value);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var index = wx.getStorageSync(utils.wordType).index;
    var reviewWords = wx.getStorageSync(utils.planStudyDays);
    var planStudyWordsOfDay = wx.getStorageSync(utils.planStudyWordsOfDay);
    var reviewWords = wx.getStorageSync(utils.planReviewWordsOfDay);
    this.setData({
      index: index,
      reviewWords: reviewWords,
      planStudyWordsOfDay: planStudyWordsOfDay,
      reviewWords: reviewWords
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})